/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HeaderPanel.java
 *
 * Created on Feb 22, 2011, 12:41:54 PM
 */

package POSTApp;
import java.text.DateFormat;
import java.util.Date;

/**
 * GUI panel for customer name and time.
 * @author Rebecca Bettencourt
 */
public class HeaderPanel extends javax.swing.JPanel {

    /** Creates new form HeaderPanel */
    public HeaderPanel() {
        initComponents();
        initTimeThread();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        customerLabel = new javax.swing.JLabel();
        timeLabel = new javax.swing.JLabel();
        customerName = new javax.swing.JTextField();

        customerLabel.setText("Customer Name:");

        timeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        timeLabel.setText("Sat Feb 15 1986 12:34:56 PST");

        customerName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerNameActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(customerLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(customerName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(timeLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(customerLabel)
                .add(timeLabel)
                .add(customerName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void customerNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_customerNameActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel customerLabel;
    private javax.swing.JTextField customerName;
    private javax.swing.JLabel timeLabel;
    // End of variables declaration//GEN-END:variables

    private void initTimeThread() {
        Thread timeThread = new Thread() {
            @Override
            public void run() {
                while (!Thread.interrupted()) {
                    try {
                        updateTime();
                        Thread.sleep(1000);
                    } catch (Exception e) {
                        break;
                    }
                }
            }
        };
        timeThread.start();
    }

    public void updateTime() {
        timeLabel.setText(DateFormat.getDateTimeInstance().format(new Date()));
    }

    public String getCustomerName() {
        return customerName.getText();
    }

    public void clearCustomerName() {
        customerName.setText("");
    }
}
